package com.fantasybaby.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 
 * @author FantasyBaby
 *
 */
@WebServlet(name = "getSessionAjax", urlPatterns = { "/getSessionAjax" })
public class SessionAjax extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public SessionAjax() {
        super();
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		String rand = (String)request.getSession().getAttribute("rand");
		String json = "{\"sessionValue\": \""+rand+"\"}";
		out.print(json);
		out.flush();
		out.close();
		System.out.println(json);
	}

}
